/*
 * @Author: Jiraiya
 * @Date: 2020-05-22 18:58:40
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-05-22 19:01:45
 * @Description: 
 */

function getReactRootElementInContainer(container: any) {
    if (!container) {
        return null;
    }

    if (container.nodeType === DOCUMENT_NODE) {
        return container.documentElement;
    } else {
        return container.firstChild;
    }
}

function shouldHydrateDueToLegacyHeuristic(container) {
    const rootElement = getReactRootElementInContainer(container);
    return !!(
        rootElement &&
        rootElement.nodeType === ELEMENT_NODE &&
        rootElement.hasAttribute(ROOT_ATTRIBUTE_NAME)
    );
}

/**
 * @description: 3
 * @param {type} 
 * @return: 
 */
function legacyCreateRootFromDOMContainer(container, forceHydrate) {
    const shouldHydrate = //是否应该调和 用于服务端的重构  当前不需要
        forceHydrate || shouldHydrateDueToLegacyHeuristic(container); // 第一次false
    // 清空容器元素所有的子节点
    if (!shouldHydrate) {
        let warned = false;
        let rootSibling;
        while ((rootSibling = container.lastChild)) {
            container.removeChild(rootSibling);
        }
    }
    // 根节点不需要异步调度
    const isConcurrent = false;
    return new ReactRoot(container, isConcurrent, shouldHydrate); //首次 false false 4
}